const storage = new LocalStorage();

class LocalStorageUtil {
  public static setOrCreate<T>(key: string, value: T): void {
    storage.setOrCreate<T>(key, value);
  }

  public static get<T>(key: string, defaultValue?: T): T {
    let v = storage.get<T>(key);
    if (!v) {
      if (defaultValue) {
        LocalStorageUtil.setOrCreate(key, defaultValue);
        return LocalStorageUtil.get(key);
      }
      return undefined;
    } else {
      return v;
    }
  }

  public static removeHistory(key: string): void {
    storage.delete(key);
  }

  public static has(key: string): boolean {
    let v = storage.has(key)
    return v;
  }


}

export default LocalStorageUtil